<template>
  <div class="container">
    <div class="app-container">
      <!-- data:表示数据源 props:表示属性 -->
      <el-tree default-expand-all :data="depts" :props="defaultProps">
        <!-- 涉及到自定义的节点，需要使用template标签 -->
        <template #default="{ data }">

          <el-row style="width: 100%; height: 40px;" align="middle" type="flex" justify="space-between">
            <el-col>{{ data.name }}</el-col>
            <el-col :span="6">
              <span class="manager">{{ data.managerName }}</span>
              <el-dropdown>
                <span class="el-dropdown-link">
                  操作<i class="el-icon-arrow-down el-icon--right" />
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>添加子部门</el-dropdown-item>
                  <el-dropdown-item>编辑部门</el-dropdown-item>
                  <el-dropdown-item>删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-col>
            <!-- <el-col :span="4">
              <span>{{ data.managerName }}</span>
            </el-col> -->
          </el-row>

        </template>
      </el-tree>
    </div>
  </div>
</template>
<script>
import { getdepartmentListAPI } from '@/api/department'
import { dataTransformTree } from '@/utils'

export default {
  name: 'Department',
  data() {
    return {
      depts: [{
        name: '传智教育',
        managerName: '张三',
        children: [
          { name: '总裁办', managerName: '李四' },
          { name: '行政部', managerName: '王六' },
          { name: '财务部', managerName: '王五' }
        ]
      }],
      defaultProps: {
        children: 'children',
        label: 'name'
      }
    }
  },
  created() {
    this.getDeptsList()
  },
  methods: {
    async getDeptsList() {
      const res = await getdepartmentListAPI()
      console.log(res)
      this.depts = dataTransformTree(res, 0)
    }
  }
}
</script>

<style lang="scss" scoped>
  .manager{
    width: 80px;
    display: inline-block;
    margin-right: 10px;
  }
</style>
